#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :file_chuli.py
# @Time      :2023/7/3 
# @Author    :CL
# @email     :1037654919@qq.com

from utils import MongoDBUtil, mongo_manager
MongoDBUtil = MongoDBUtil()
deviantart_images = mongo_manager("deviantart_images", db="car_images")



bianlilist = []
def test_1():
    path1 = 'concept car/bianlilist.txt'
    path2 = 'car v1/bianlilist.txt'
    path3 = 'SUM/bianlilist.txt'
    path4 = 'SUM/bianlilist.txt'
    global bianlilist
    with open('deviantart/' + path1, encoding='utf-8') as f:
        for line in f:
            print(line)
            bianlilist.append(line)
        # print(bianlilist)
        print(len(bianlilist))
    f.close()
    with open('deviantart/' + path2, encoding='utf-8') as f:
        for line in f:
            print(line)
            bianlilist.append(line)
        # print(bianlilist)
        print(len(bianlilist))
    f.close()
    with open('deviantart/' + path3, encoding='utf-8') as f:
        for line in f:
            print(line)
            bianlilist.append(line)
        # print(bianlilist)
        print(len(bianlilist))
    f.close()

    bianlilist = list(set(bianlilist))
    print(len(bianlilist))
    with open('deviantart/' + path4, 'w') as f:
        for line in bianlilist:
            f.write(line)
    f.close()

def test_2():
    global bianlilist
    with open('deviantart/bianlilist.txt',encoding='utf-8') as f:
        for line in f:
            bianlilist.append(line.strip('\n'))
    f.close()
    print(bianlilist[:10])
    print(len(bianlilist))
    bianlilist = list(set(bianlilist))
    print(len(bianlilist))
    seeds = deviantart_images.findAll({'status':None})
    id= 0
    lisss=[]
    for seed in seeds:
        lisss.append(seed['url'])
        if seed['url'] in bianlilist:
            id += 1
            seed['status'] = 'success'
            deviantart_images.updateOne({'_id': seed['_id']}, seed)
    print(id)
    print(lisss[:10])
    deviantart_images.close()
if __name__ =="__main__":

    test_2()


    # deviantart_images = mongo_manager("deviantart_images", db="car_images")
    # seeds = deviantart_images.findAll()
    # for seed in seeds:
    #
    #     seed['status'] = None
    #     deviantart_images.updateOne({'_id': seed['_id']}, seed)
    #
    # deviantart_images.close()
